package com.softeem.blog.dao;

import java.util.List;

import com.softeem.blog.entity.Link;
import com.softeem.blog.utils.DBUtils;

public class LinkDAO implements IBaseDAO<Link>{

	@Override
	public boolean insert(Link t) {
		String sql  = "insert into link(title,summary,url,sort) values(?,?,?,?)";
		return DBUtils.exeUpdate(sql, t.getTitle(),t.getSummary(),t.getUrl(),t.getSort());
	}

	@Override
	public boolean deleteById(int id) {
		String sql = "delete from link where id=?";
		return DBUtils.exeUpdate(sql, id);
	}

	@Override
	public boolean update(Link t) {
		String sql = "update link set title=?,summary=?,url=? where id=?";
		return DBUtils.exeUpdate(sql, t.getTitle(),t.getSummary(),t.getUrl(),t.getId());
	}

	@Override
	public Link findById(int id) {
		String sql = "select * from link where id=?";
		return DBUtils.queryOne(Link.class, sql, id);
	}

	@Override
	public List<Link> findByPage(int pageSize, int pageNow) {
		String sql = "select * from link limit ?,?";
		return DBUtils.queryList(Link.class, sql, (pageNow-1)*pageSize,pageSize);
	}

	@Override
	public int getCount() {
		String sql = "select count(*) from link";
		return DBUtils.queryCount(sql);
	}

	public Link findByTitle(String title) {
		String sql = "select * from link where title=?";
		return DBUtils.queryOne(Link.class, sql, title);
	}

}
